# -*- coding: utf-8 -*-
"""
 ----------------------------------------
|File Name:     time_to_obtain
|Author:        WYT
|date:          2020/6/19
 ----------------------------------------
|  Change Activity:
|                   2020/6/19:
-----------------------------------------
"""
import json
import time

from timeToObtain.db_con import hitech_pool, dict_cursor
from util.inform.sendEmail import sendEmail


def get():
    print("start".center(105, "~"))
    sleep_time = 60 * 30
    time.sleep(sleep_time)
    sql = """select s.* from ent_yearstatus e,ent_res_status s where 
    e.`year`=s.year and e.co_id=s.co_id and s.ul_status=0 and e.`status`=2 and s.co_id not in (307566, 29330, 463094)"""
    client = hitech_pool.connection()
    cursor = client.cursor(cursor=dict_cursor)
    data = None
    try:
        cursor.execute(sql)
        data = cursor.fetchall()
    except Exception as err:
        a = sendEmail(subject="timeToObtain", content="查询错误: {}".format(err), target="18235693860@163.com")
        a.send_mail()
    if data != {} and data is not None:
        content = ["{}\n{}".format(i.get("entname"),json.dumps(i)) for i in data]
        a = sendEmail(subject="timeToObtain", content="\n{}\n".format("-" * 10).join(content))
        a.send_mail()


if __name__ == '__main__':
    get()

